package com.assignwork.vo;

import io.swagger.annotations.ApiModel;
import lombok.Data;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springblade.core.tool.utils.DateUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.springblade.core.tool.utils.Func;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * (WorkLineLogMachine)VO
 * @since 2024-05-28 11:01:02
 */
@Data
@ApiModel(value = "WorkLineLogMachineVO", description = "")
public class WorkLineLogMachineVO  {

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long planId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long arrangeId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long lineId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long logId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long assignWorkId;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long assignWorkInfoId;

    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    private LocalDateTime beginTime;

    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    private LocalDateTime endTime;

    private String workerNo;
    private String workerName;
    private String mechanicalName;
    private String mechanicalNo;
    private String machineKind;
    private String machineKindName;

    public String getEndTimeStr() {
        if (endTime != null) {
            return DateUtil.format(endTime, "HH:mm");
        }
        return "";
    }

    public String getBeginTimeStr() {
        if (beginTime != null) {
            return DateUtil.format(beginTime, "HH:mm");
        }
        return "";
    }

    public String getBeginEndTimeStr() {
        if (Func.isNotBlank(getBeginTimeStr()) && Func.isNotBlank(getEndTimeStr())) {
            return getBeginTimeStr() + "~" + getEndTimeStr();
        }

        return "";
    }

    public static Map list2Map(List<WorkLineLogMachineVO> ls) {
        return ls.stream().collect(Collectors.groupingBy(WorkLineLogMachineVO::getAssignWorkInfoId));
    }
}

